package com.gx.recruitment.controller;

import com.gx.recruitment.entity.Comp_info;
import com.gx.recruitment.service.CompService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class CompController {
    @Resource
    private CompService compService;

    @PostMapping("/company/add")
    public Map<String, Object> registerCompany(String compname, String comppass, String compemail) {
        Map<String,Object> map =new HashMap<>();
        Comp_info comp_info = new Comp_info();
        comp_info.setCompName(compname);
        comp_info.setCompPass(comppass);
        comp_info.setCompEmail(compemail);
        List<Comp_info> comps = compService.findbyCompName(compname);
        if(comps != null && comps.size() > 0){
            map.put("msg","用户名已经存在");
            return map;
        }else {
            int res = compService.insertComp(comp_info);
            if (res == 0) {
                map.put("msg","success");
                return map;
            } else {
                map.put("msg","fail");
                return map;
            }
        }
    }

    @PostMapping("/company/login")
    public Map<String,Object> loginCompany(String compname,String comppass){
        Map<String,Object> map =new HashMap<>();
        List<Comp_info> comps = compService.loginComp(compname,comppass);
        System.out.println(comps);
        if (comps !=null && comps.size()>0){
            map.put("msg","success");
            map.put("compid",comps.get(0).getCompId());
            return map;
        }else {
            map.put("msg","fail");
            return map;
        }
    }
}